﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BurningADiscImage
{
  class Program
  {

    // This script burns data files to disc in a single session 
    // using files from a single directory tree.
    // Copyright (C) Microsoft Corp. 2006

    // *** CD/DVD disc file system types
    public const int FsiFileSystemISO9660 = 1;
    public const int FsiFileSystemJoliet = 2;
    public const int FsiFileSystemUDF102 = 4;


    static void Main(string[] args)
    {

      dynamic Index;              // Index to recording drive.
      dynamic recorder;            // Recorder object
      dynamic Path;             // Directory of files to burn
      dynamic Stream;              // Data stream for burning device

      //Index = 1;            // Second drive on the system
      Index = 0;            // First drive on the system

      //Path = @"g:\BurnDir";     // Files to transfer to disc
      Path = @"c:\BurnDir";



      // Create a DiscMaster2 object to connect to optical drives.
      dynamic g_DiscMaster;
      g_DiscMaster = new IMAPI2.MsftDiscMaster2();
      
      // Create a DiscRecorder object for the specified burning device.
      dynamic uniqueId;
      recorder = new IMAPI2.MsftDiscRecorder2();
      uniqueId = g_DiscMaster.Item(Index);
      recorder.InitializeDiscRecorder(uniqueId);

      // Create an image stream for a specified directory.
      dynamic FSI;                 // Disc file system
      dynamic Dir;                 // Root directory of the disc file system
      dynamic dataWriter;

      // Create a new file system image and retrieve root directory
      FSI = new IMAPI2FS.MsftFileSystemImage();
      Dir = FSI.Root;

      //Create the new disc format and set the recorder
      dataWriter = new IMAPI2.MsftDiscFormat2Data();
      dataWriter.Recorder = recorder;
      dataWriter.ClientName = "IMAPIv2 TEST";

      FSI.ChooseImageDefaults(recorder);

      // Add the directory and its contents to the file system 
      Dir.AddTree(Path, false);

      // Create an image from the file system
      dynamic result;
      result = FSI.CreateResultImage();
      Stream = result.ImageStream;

      // Write stream to disc using the specified recorder.
      Console.WriteLine("Writing content to disc...");
      dataWriter.Write(Stream);

      Console.WriteLine("----- Finished writing content -----");

    }

    

  }
}
